# -*- coding: utf-8 -*-
"""
@Time ： 2020/11/23 15:25
@Auth ： Mr. William 1052949192
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：json格式传参
页面：https://b.zhulogic.com/case
"""
import json

import requests


# # 第一种方式，json参数传
# # 两种情况，你可以直接传字符串，如果不成功，就传字典
# session = requests.session()
# print(session.headers)
# result = session.post('https://b.zhulogic.com/designer_api/case',
#                       json={"pageSize":9,"pageNum":1,"sort":214,"screen":-1,"childrenSpaceId":0,"spaceId":0,"styleId":0})
# print(result.text)
# # 用json=去传参，自动会在头里面加上'Content-Type': 'application/json'
# print(result.request.headers)


# 使用data传参，你可以直接传字符串，如果不成功，就传字典
session = requests.session()
print(session.headers)
# 用data传，必须自己指定这个头
session.headers['content-type'] ='application/json;charset=UTF-8'
result = session.post('https://b.zhulogic.com/designer_api/case',
                      data='{"pageSize":2,"pageNum":1,"sort":214,"screen":-1,"childrenSpaceId":0,"spaceId":0,"styleId":0}')
# print(result.text)
# print(result.request.headers)

# jsonpath应用
import jsonpath

res = json.loads(result.text)
coverFile_id = jsonpath.jsonpath(res,'$.data.list.[0].coverFile.id')[0]
print(coverFile_id)

